package priv.pront.code.lanqiao.competition.course.date0402;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-04-02 15:40
 */
public class 砍树 {
    static int n,m,left, right;
    static int[] arr;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();  // 树木的数量
        m = scanner.nextInt();  // 需要的木材总长度
        arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        left = arr[0];
        right = arr[n - 1];
        while (left < right) {
            int mid = left + (right - left) / 2;
            if(check(mid) > m){
                left = mid + 1;
            } else if (check(mid) < m) {
                right = mid;
            }else{
                System.out.println(mid);
                return;
            }
        }
        System.out.println(left);
    }

    private static long check(int k) {
        long sum = 0;
        for (int i : arr) {
            sum += Math.max(0, i - k);
        }
        return sum;
    }
}
